package com.uniview.mvpdemo.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.util.Log;

import com.google.gson.Gson;
import com.uniview.mvpdemo.R;
import com.uniview.mvpdemo.adapter.Main2Adpter;
import com.uniview.mvpdemo.base.BaseActivity;
import com.uniview.mvpdemo.bean.Login;
import com.uniview.mvpdemo.mvp.Main2Contract;
import com.uniview.mvpdemo.mvp.Main2Presenter;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Main2Activity extends BaseActivity implements Main2Contract.View {
    private static final String TAG = Main2Activity.class.getSimpleName();
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;

    private Main2Contract.Presenter presenter;
    private Main2Adpter adpter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        if (intent != null) {
            String loginInfo = intent.getStringExtra("login");
            Login login = new Gson().fromJson(loginInfo, Login.class);
            Log.e(TAG, "onCreate: login = " + login.toString());
        }

        new Main2Presenter(this);
    }

    @Override
    public void setPresenter(Main2Contract.Presenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public void initViews() {
        adpter = new Main2Adpter(getSupportFragmentManager());
        viewPager.setAdapter(adpter);

        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
    }

    @Override
    public void onLoading(String text) {
        showLoading(text);
    }

    @Override
    public void loadingComplete() {
        hideLoading();
    }

    @Override
    public void loadingError(String error) {

    }
}
